<?php 

 /*****
 * @return 返回值说明：
 * 0 --上传成功
 * 1 --上传失败
 * 2 --链接缺少参数
 * 3 --文件超过最大限制
 * 4 --签证验证失败
 */
class upload{
	
	private $config = array(
		'maxSize'=>0, //上传的文件大小限制(最大为500KB)
		'rootpath' =>'./files/', //文件存放根目录
		'filename' =>'', //文件名
		'signstr' =>'c6m9X28ghwQd',  //签名验证
	
	);	
	private $md5;
	private $sign;	
	
	function __construct($config = array(),$md5,$sign){
		
		 $this->config   =   array_merge($this->config, $config);	 
		 $str = md5($md5.$this->config['signstr']);
		 if($str!=$sign){
			 exit();			
		 }		 		
	}
	function download(){		
		$filename = $this->config['rootpath'].$this->config['filename'];
		
		if(file_exists($filename)){
			$file_size=filesize($filename);
			$file_name = $this->config['filename'];
			Header("Content-type: image/png");
			Header("Accept-Ranges: bytes");
			Header("Accept-Length: ".$file_size);
			Header("Content-Disposition: attachment; filename=".$file_name);
			readfile("$filename");
			exit();	
		}else{			
			exit();
		}		
	}
	function get_contents()
	{				
	    $xmlstr= file_get_contents("php://input");
		$size = strlen($xmlstr);
		if($size>$this->config['maxSize']){
			
			 exit();
			return false;
		}
		
	    $filename=$this->config['filename'];						
		$path = $this->config['rootpath'].$filename;					
	    if(!file_put_contents($path,$xmlstr))
	    {
	        exit();
	    }

	}
	

}

	

?>